<?php
/**
 * 环信发送消息
 * zhouliang
 * 2020.09.10
 */

namespace App\Services\Tools;

use App\Enums\RoomPKEnum;
use function AlibabaCloud\Client\json;

class PushChatService
{

    const TEMPLATE_LOTTERY_CRYSTAL = 1004; //1004 抽奖-水晶
    const TEMPLATE_LOTTERY_TURNTABLE = 6070; //1005 抽奖-转盘

    const AREA_ALL = 0; //全部
    const AREA_ROOM = 1;//房间
    const AREA_LUCKY = 2;//幸运
    const AREA_WELCOME = 3;//欢迎
    const AREA_WORLD = 4;//世界
    const AREA_SYSTEM = 5;//系统
    const AREA_LUCKY_REBATE = 6;//暴击


    const CHAT_GET_IN_ROOM = 6001;//公屏消息-加入房间
    const CHAT_GIVE_GIFT = 6002;//公屏消息-送礼物
    const CHAT_GIVE_GIFT_PRIVATE = 6003;//私聊消息-送礼物
    const CHAT_FISH = 6004;//公屏消息-小猫钓鱼礼物消息
    const CHAT_BALL = 6005;//公屏消息-球球大作战
    const CHAT_PIT = 6006;//公屏消息-上下麦
    const CHAT_KICK_OUT = 6007;//公屏消息-踢出房间
    const CHAT_SHUT_UP = 6008;//公屏消息-禁麦|解禁
    const CHAT_BANNED = 6009;//公屏消息-禁言|解禁
    const CHAT_FACE = 6010;//公屏消息-发送表情
    const CHAT_ROLL = 6011;//公屏消息-摇骰子
    const CHAT_CHAT_ROOM = 6012;//公屏消息-普通文本消息
    const CHAT_OFFICIAL_NOTICE = 6013;//公屏消息-官方公告
    const CHAT_GREETING = 6014;//公屏消息-房间欢迎语
    const CHAT_CHAT_PRIVATE = 6015;//私聊消息-普通文本消息
    const CHAT_NEW_USER = 6016;//公屏消息-新用户加入平台
    const CHAT_BALL_START = 6017;//公屏消息-开球
    const CHAT_BALL_THROW = 6018;//公屏消息-丢球
    const CHAT_BALL_SHOW = 6019;//公屏消息-亮球
    const CHAT_SOUND_EFFECT = 6020;//公屏消息-音效改变
    const OPEN_BLIND_BOX = 6021;//开盲盒送礼物公屏消息
    const NOTICE_BOX = 6022;//开盲盒送礼物提示消息
    const ORDER_MESSAGE = 6023;//订单消息
    const DEMAND_MESSAGE = 6024;//发布派单后发送公屏消息
    const CP_APPLY = 6025;//人脉CP绑定申请私聊消息
    const CP_APPLY_AGREE = 6026;//人脉CP绑定同意消息
    const CP_APPLY_REFUSE = 6027;//人脉CP绑定拒绝消息
    const CP_APPLY_DIY_NICKNAME = 6028;//人脉自定义称谓消息
    const MARRY_APPLY = 6029;//人脉结婚申请消息
    const CONNECTION_INTIMACY_USED = 6030;//人脉亲密卡使用成功消息
    const CONNECTION_UNBIND = 6031;//人脉解绑消息
    const CHAT_AUCTION_ABORT = 6032;//拍卖中断发送公屏消息
    const CP_APPLY_EXPIRE = 6033;//人脉CP绑定申请过期私聊消息
    const SYSTEM_NOTICE = 6034;//公共的系统消息通知
    const CHAT_USER_FAVOR_ROOM = 6035;//用户在房内关注房间
    const CHAT_THEME_HEAD_LINE = 6036;//头条消息
    const CHAT_THEME_CHAT = 6037;//话题广场消息
    const WELCOME_USER_JOIN_ROOM = 6050;//欢迎他人进入房间（客户端用）
    const CHAT_GIVE_GIFT_BIG = 6038;//大礼物全服消息
    const OPEN_BLIND_BOX_BIG = 6040;//用户开他人送盲盒开出大礼物
    const CP_FIRST_BIND_CHAT = 6060;//绑定CP文案推送
    const CHAT_LUCKY_TREE = 6025;//公屏消息-许愿树礼物消息
    const CHAT_RECOMMEND_ANCHOR_ROOM = 6107; //用户注册推荐房间推送

    const HEART_RECORD = 6300;  //心动连线推送
    const HEART_EXTEND = 6301;  //心动连线续费推送，使客户端刷新时间
    const HEART_SEND = 6302;  //心动连线推送，使客户端显示文字
    const HEART_TIMEOUT = 6303; //心动连线主播掉线
    const HEART_CARD_GAME = 6304;//心动连线卡牌游戏
    const HEART_FACE = 6305; //心动连线发送表情
    const HEART_CONNECTION_ENC = 6306;//心动连线超时推送主播结束
    const HEART_CONNECTION_GIFT = 6307;//心动连线推送礼物

    const CHAT_GASHAPON = 6070;//公屏消息-扭蛋
    const CHAT_PIRATE = 6071;//公屏消息-海盗
    //pk
    const CHAT_ROOM_PK_START = 7110;
    const CHAT_ROOM_PIT_PK_START = 7111;
    const CHAT_ROOM_PK_VICTORY = 7112;
    const CHAT_ROOM_PK_DRAW = 7113;
    const CHAT_ROOM_PIT_PK_VICTORY = 7114;
    const CHAT_ROOM_PIT_PK_DRAW = 7115;
    const CHAT_ROOM_PIT_PK_DRAW_SCORE = 7116;

    const CHAT_SCREEN_START = 6100; //我要上公屏创建 推送
    const CHAT_SCREEN_END = 6101;///我要上公屏结束 推送

    const CHAT_REBATE_GIFT_GIVE = 6201; // 返利礼物推送
    const CHAT_UNLOCK_CARD = 6203; // 解锁卡片
    const CHAT_RECOMMEND_BROWSE_ACCOMPANY_MESSAGE = 6111;//陪玩-访问主页系统推送

    const CHAT_BROWSE_ACCOMPANY = 6206;//访问主页私聊陪玩
    const CHAT_NEW_PIRATE = 6071;//公屏消息-海盗

    const BROADCAST_LOTTERY_CRYSTAL = 6075;//广播消息-水晶
    const BROADCAST_LOTTERY_CRYSTAL_CRIT = 6076;//广播消息-水晶

    const CHAT_PET = 6081;//公屏消息-海盗

    const CHAT_FIRST_ACCOMPANY = 6205;//陪玩私聊消息
    const CHAT_RECOMMEND_ACCOMPANY_ORDER = 6109; //陪玩创建用户推送
    const CHAT_RECOMMEND_ACCOMPANY_MESSAGE = 6110;//陪玩私聊消息

    const NEW_YEAR_LOTTERY = 8030;//公屏消息-海盗
    const GROUP_CHAT_TEXT_MESSAGE = 8040; // 纯文本消息
    const GROUP_CHAT_AT_MESSAGE = 8041; // @消息
    const GROUP_CHAT_IMAGE_MESSAGE = 8042; // 图片消息
    const GROUP_CHAT_AUDIO_MESSAGE = 8043; // 音频消息
    const GROUP_CHAT_VIDEO_MESSAGE = 8044; // 视频消息
    const GROUP_CHAT_BULLETIN_MESSAGE = 8045; // 公告消息
    const GROUP_CHAT_POSITION_MESSAGE = 8046; // 位置消息
    const GROUP_CHAT_GIFT_MESSAGE = 8047; // 送礼消息
    const GROUP_CHAT_SHARE_ROOM_MESSAGE = 8048; // 分享房间
    const GROUP_CHAT_SHARE_PARTY_MESSAGE = 8049; // 分享派对
    const GROUP_CHAT_NOTIFY_MESSAGE = 8050; // 通知消息
    const GROUP_CHAT_SHARE_CARD_MESSAGE = 8051; // 分享卡片

    const GAME_PUSH_STATUS = 8888;  // 通用 游戏推送  {系统推送 ， 幸运推送}

    public $user_id, $room_id, $topic_room, $topic_client, $topic_heart;

    public function __construct($user_id = 0, $room_id = 0)
    {
        $this->user_id = $user_id;
        $this->room_id = $room_id;
        $this->topic_heart = $this->room_id;

        $this->topic_room = 'room_' . $this->room_id;
        $this->topic_client = 'user_' . $this->user_id;
    }

    /**
     * @param $ext
     * @param $giftData
     * @param $broadcastPushData
     * 所有游戏公共推送！v 版本 juju
     */
    public function game($ext, $notifyPush,$broadcastPushData){

        $info = [
            'broadcastPush'=> $broadcastPushData ,
            'notifyPush'=> $notifyPush
        ];
        $ext['type'] = self::GAME_PUSH_STATUS;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        // ['broadcastPush'=> {} , 'notifyPush'=> {}]
        $this->rcQueueNew('room', $info, $ext);
    }

    /**
     * @param $targetId
     * @param array $message
     * @param array $ext
     * @param string $senderId
     * @param string $type
     * @param int $isIncludeSender
     * 游戏推送！v 版本 juju
     */
    public function rcQueueNew($targetId, $message = [], $ext = [], $senderId = 'system', $type = 'RC:TxtMsg', $isIncludeSender = 0)
    {
        /**
         * @var $rcService RongCloudService
         */
        $data = [
            'content' => $message,
            'extra' => $ext
        ];
        $rcService = app('rongcloud');
        $rcService->queue($senderId, $targetId, $data, 0, $type, $isIncludeSender);
    }

    public function setUser($user_id)
    {
        $this->user_id = $user_id;
        $this->topic_client = 'user_' . $user_id;
    }

    public function setRoom($room_id)
    {
        $this->room_id = $room_id;
        $this->topic_room = 'room_' . $room_id;
    }

    private function push($targetId, $message, $ext = [], $senderId = 'system', $type = 'RC:TxtMsg', $isIncludeSender = 0)
    {
        $this->rcQueue($targetId, $message, $ext, $senderId, $type, $isIncludeSender);
    }

    public function rcQueue($targetId, $message, $ext = [], $senderId = 'system', $type = 'RC:TxtMsg', $isIncludeSender = 0)
    {
        /**
         * @var $rcService RongCloudService
         */
        $data = [
            'content' => $message,
            'uni_key' => uniqidReal(),
            'extra' => $ext
        ];
        $rcService = app('rongcloud');
        $rcService->queue($senderId, $targetId, $data, 0, $type, $isIncludeSender);
    }

    //用户进入房间
    public function getInRoom($ext = [])
    {
        $ext['type'] = self::CHAT_GET_IN_ROOM;
        $ext['action'] = 3;
        $message = '<font color="#FFCB00">加入直播间</font>';
        $this->push($this->topic_room, $message, $ext);
    }

    //用户在房间赠送礼物
//     public function giveGift($get_users, $ext = [])
//     {
//         $ext['type'] = self::CHAT_GIVE_GIFT;
//         $ext['action'] = 3;
//         $message = '<font color="#FF6C6C">送了</font><font color="#B6A2FF">'.implode('，',
//                 $get_users).'</font><font color="#FF6C6C">'.$ext['gift_name'].'x'.$ext['gift_num'].'</font>';
//         $this->push($this->topic_room, $message, $ext);
// //          Log::record('修改后的推送：'.$message);
//     }


    //用户开启盲盒提示消息
    public function noticeBox($target, $gift_given_user_ids = [], $ext = [])
    {
        $ext['type'] = self::NOTICE_BOX;
        $ext['action'] = 3;
        $message = '<font color="#FF6C6C">送给</font><font color="#B6A2FF">' . implode('，', $gift_given_user_ids) . '</font>';
        $this->push($target, $message, $ext);
    }

    //上下麦
    public function pit($message, $ext)
    {
        $ext['type'] = self::CHAT_PIT;
        $ext['action'] = 3;
        $message = '<font color="#9866FF">' . $message . '</font>';
        $this->push($this->topic_room, $message, $ext);
    }

    //踢出房间
    public function kickOut($ext)
    {
        $ext['type'] = self::CHAT_KICK_OUT;
        $ext['action'] = 3;
        $message = '<font color="#FFFFFF">被踢出房间</font>';
        $this->push($this->topic_room, $message, $ext);
    }

    //公屏消息-普通文本消息
    public function chatRoom($message, $ext)
    {
        $ext['type'] = self::CHAT_CHAT_ROOM;
        $ext['action'] = 2;
        $this->push($this->topic_room, $message, $ext);
    }

    //下订单环信消息
    public function orderProduce($targetId, $param = [], $senderId)
    {
        $ext['type'] = self::ORDER_MESSAGE;
        $ext['em_is_order'] = true;
        $ext['order_status'] = $param['status'];
        $ext['order_title'] = $param['title'];
        $ext['order_desc'] = $param['desc'];
        $ext['order_type'] = $param['type'];
        $ext['order_id'] = $param['order_id'];
        $ext['user_id'] = $param['user_id'];
        $ext['nickname'] = $param['nickname'];
        $ext['sex'] = $param['sex'];
        $ext['avatar'] = $param['avatar'];
        $this->push('user_' . $targetId, '[订单消息]', $ext, 'user_' . $senderId);
    }

    //发布派单后发送公屏消息
    public function demandMessage($message)
    {
        $ext['type'] = self::DEMAND_MESSAGE;
        $ext['action'] = 9;
        $ext['room_id'] = $this->room_id;
        $this->push($this->topic_room, $message, $ext);
    }

    //人脉申请CP绑定请求发送申请消息
    public function cpApply($targetId, $ext, $senderId)
    {
        $ext['type'] = self::CP_APPLY;
        $message = '用户' . $ext['nickname'] ?? '' . '（' . $ext['user_code'] ?? '' . '）' . '申请与你绑定称谓CP';
        $this->push('user_' . $targetId, $message, $ext, 'user_' . $senderId);
    }

    //人脉申请CP绑定请求过期消息
    public function cpApplyExpire($targetId, $ext = [], $senderId)
    {
        $ext['type'] = self::CP_APPLY_EXPIRE;
        $this->push('user_' . $targetId, '绑定申请已失效', $ext, 'user_' . $senderId);
    }

    //人脉申请CP绑定请求同意消息
    public function cpApplyAgree($targetId, $type, $ext = [], $senderId)
    {
        $ext['type'] = self::CP_APPLY_AGREE;
        $message = '恭喜二位喜结' . ($type == 1 ? 'cp' : '良缘');
        $this->push('user_' . $targetId, $message, $ext, 'user_' . $senderId);
    }

    //人脉申请CP绑定请求拒绝消息
    public function cpApplyRefuse($targetId, $ext = [], $senderId)
    {
        $ext['type'] = self::CP_APPLY_REFUSE;
        $this->push('user_' . $targetId, '感谢您的喜欢，我们不合适！', $ext, 'user_' . $senderId);
    }

    //人脉自定义称谓消息
    public function cpApplyDiyNickname($targetId, $ext = [], $senderId)
    {
        $ext['type'] = self::CP_APPLY_DIY_NICKNAME;
        $this->push('user_' . $targetId, '嗨，以后我就叫你 ' . $ext['user_nickname'], $ext, 'user_' . $senderId);
    }

    //人脉申请结婚请求发送申请消息
    public function marryApply($targetId, $ext, $senderId)
    {
        $ext['type'] = self::MARRY_APPLY;
        $message = '用户' . $ext['nickname'] ?? '' . '（' . $ext['user_code'] ?? '' . '）' . '申请与你结婚';
        $this->push('user_' . $targetId, $message, $ext, 'user_' . $senderId);
    }

    //人脉亲密卡使用成功消息
    public function intimacyUsed($targetId, $ext = [], $senderId)
    {
        $ext['type'] = self::CONNECTION_INTIMACY_USED;
        $this->push('user_' . $targetId, '我使用了亲密卡，我们继续提升亲密等阶吧！', $ext, 'user_' . $senderId);
    }

    //人脉解绑消息
    public function unbind($targetId, $ext = [], $senderId)
    {
        $title = '';
        if ($ext['type'] == 2 && $ext['married']) {
            $title = '婚姻';
        } elseif ($ext['type'] == 2 && !$ext['married']) {
            $title = 'CP';
        } else {
            $title = '亲密';
        }
        $message = '您们的' . $title . '关系已解除';
        $ext['type'] = self::CONNECTION_UNBIND;
        $this->push('user_' . $targetId, $message, $ext, 'user_' . $senderId);
    }

    //拍卖中断
    public function auctionAbort($message)
    {
        $ext['type'] = self::CHAT_AUCTION_ABORT;

        $this->push($this->topic_room, $message, $ext);
    }

    //公共的系统消息通知
    public function systemNotice($message)
    {
        $ext['type'] = self::SYSTEM_NOTICE;

        $this->push($this->topic_room, $message, $ext);
    }

    //发头条公屏通知 （全服通知）
    public function themeStriveHeadlineChat($message, $ext)
    {
        $ext['type'] = self::CHAT_THEME_HEAD_LINE;
        $ext['action'] = 3;
        $ext['show_area'] = [
            self::AREA_ALL,
            self::AREA_WORLD,
        ];
        // $message = '<font color="#ECE9FF">'.$message.'</font>';
        //全服推送
        $this->push('theme_push', $message, $ext);
    }

    //话题广场推送消息
    public function themeStriveChat($message, $ext)
    {
        $ext['type'] = self::CHAT_THEME_CHAT;
        $ext['action'] = 3;
        $ext['show_area'] = [
            self::AREA_WORLD,
        ];
        $message = '<font color="#FFFFFF">' . $message . '</font>';
        //全服推送
        $this->push('theme_push', $message, $ext);
    }

    //首次结缘推送房间用户消息
    public function sendFirstBindCpChat($message, $ext = [])
    {
        $ext['type'] = self::CP_FIRST_BIND_CHAT;
        $ext['action'] = 3;
        $ext['show_area'] = [
            self::AREA_ROOM,
        ];
        $ext['show_label_id'] = [
            self::AREA_ROOM,
        ];
        $this->push($this->topic_room, $message, $ext);
    }

    //推送盲盒礼物
    // 打开盲盒 已增加user_label
    public function openConnectGift($message, $ext = [])
    {
        $ext['action'] = 1;
        $ext['type'] = self::OPEN_BLIND_BOX;
        $ext['show_label_id'] = [
            self::AREA_LUCKY
        ];
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ROOM,
        ];
        $this->push($this->topic_room, $message, $ext);
    }


    public function broadcastOpenConnectGift($message, $ext = [])
    {
        $ext['show_label_id'] = [
            self::AREA_LUCKY
        ];
        $ext['show_area'] = [
            self::AREA_LUCKY,
        ];
        $ext['type'] = self::OPEN_BLIND_BOX_BIG;
        $this->push('room', $message, $ext);
        return true;
    }

    //我要删公屏活动结束
    public function screenActivityEnd($message, $ext = [])
    {
        $ext['show_label_id'] = [
            self::AREA_SYSTEM,
        ];
        $ext['show_area'] = [
            self::AREA_ALL,
            self::AREA_ROOM,
        ];
        $ext['type'] = self::CHAT_SCREEN_END;
        $this->push($this->topic_room, $message, $ext);
        return true;
    }

    //国庆节游戏推送
    public function activity_game($txt, $ext = [])
    {
        $ext['action'] = 1;
        $ext['type'] = self::CHAT_FISH;
        $ext['show_label_id'] = [
            self::AREA_LUCKY
        ];
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ROOM,
        ];
        $this->push('room', $txt, $ext);
    }


    public function gashaponNew($ext, $gift, $levelInfo)
    {
        $txt = "<font color='#BDF1FF'>" . $levelInfo->name . " </font>";
        $txt .= "<font color='#3AA4E6'>" . $ext['nickname'] . " </font>";
        $txt .= "<font color='#BDFFD1'>在奇遇锦囊中意外获得 </font>";
        $txt .= '<font color="#FFE6BC">' . $gift->price . '</font>';
        $txt .= '<font color="#BDFFD1"> 金币的</font>';
        $txt .= '<font color="#3ADBE6">' . $gift->name . ' x ' . $gift->count . '</font>';
        $txt .= '<font color="#BDFFD1"> 礼物，运气爆棚！</font>';
        $ext['type'] = self::CHAT_NEW_PIRATE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }

    public function gashaponNewCritical($ext, $gift, $levelInfo)
    {
        $txt = "<font color='#FFD769'>" . $levelInfo->name . " </font>";
        $txt .= "<font color='#E68D3A'>" . $ext['nickname'] . " </font>";
        $txt .= "<font color='#46E0FF'>在许愿中获得 </font>";

        $txt .= '<font color="#FFEB6A">' . $gift['price'] . '</font>';
        $txt .= '<font color="#46E0FF"> 金币的等级专属礼物 </font>';
        $txt .= '<font color="#E6573A">' . $gift['name'] . '</font>';
        $txt .= '<font color="#46E0FF"> ，吉人天相！</font>';
        $ext['type'] = self::CHAT_LUCKY_TREE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }

    public function lottery($plateName, $ext, $gift)
    {
        $txt = "<font color='#ECE9FF'>在{$plateName} 寻得</font>";
        $txt .= '<font color="#ECE9FF">价值</font>';
        $txt .= '<font color="#2FE5FF">' . $gift->price . '</font>';
        $txt .= '<font color="#ECE9FF">声喵币的</font>';
        $txt .= '<font color="#2FE5FF">' . $gift->name . ' x ' . $gift->count . '</font>';
        $txt .= '<font color="#ECE9FF"> 宝物</font>';
        $ext['type'] = self::CHAT_PIRATE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }

    public function lottery3($ext, $gift)
    {
        $txt = "<font color='#ECE9FF'>驾驶时空穿梭机前往过去/未来，途中获得</font>";
        $txt .= '<font color="#ECE9FF">价值</font>';
        $txt .= '<font color="#2FE5FF">' . $gift->price . '</font>';
        $txt .= '<font color="#ECE9FF">金币的奖品</font>';
        $txt .= '<font color="#2FE5FF">' . $gift->name . ' x ' . $gift->count . '</font>';
        $ext['type'] = self::CHAT_GASHAPON;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }

    public function gashapon($ext, $gift)
    {
        $txt = "<font color='#ECE9FF'>在霓虹扭蛋机中 扭出</font>";
        $txt .= '<font color="#ECE9FF">价值</font>';
        $txt .= '<font color="#2FE5FF">' . $gift->price . '</font>';
        $txt .= '<font color="#ECE9FF">声喵币的</font>';
        $txt .= '<font color="#2FE5FF">' . $gift->name . ' x ' . $gift->count . '</font>';
        $txt .= '<font color="#ECE9FF"> 奖品</font>';
        $ext['type'] = self::CHAT_GASHAPON;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }


    // 赠送礼物v35
    public function giveGift($message, $ext = [])
    {
        $ext['type'] = self::CHAT_GIVE_GIFT;
        $ext['action'] = 3;
        $ext['show_area'] = [
            self::AREA_ROOM,
            self::AREA_ALL,
        ];
        $this->push($this->topic_room, $message, $ext);
    }

    public function giveRebateGift($message, $ext = [])
    {
        $ext['type'] = self::CHAT_REBATE_GIFT_GIVE;
        $ext['action'] = 3;
        $ext['show_area'] = [
            self::AREA_ROOM,
            self::AREA_ALL,
        ];
        $this->push($this->topic_room, $message, $ext);
    }

    // 赠送礼物广播 //有人在房间内送出单个礼物价值超过13140元后
    public function airingGiveGift($message, $ext = [])
    {
        $ext['type'] = self::CHAT_GIVE_GIFT_BIG;
        $ext['action'] = 3;
        $ext['show_area'] = [
            self::AREA_ROOM,
            self::AREA_ALL,
        ];
        $this->push('room', $ext, 0);
    }


    public function luckyRebateGift($user, $targetNickname, $coin, $gift)
    {
        $txt = '<font color="#ECE9FF">给</font>';
        $txt .= '<font color="#2FE5FF">' . $targetNickname . '</font>';
        $txt .= '<font color="#ECE9FF">送出</font>';
        $txt .= '<font color="#2FE5FF">' . $gift->name . '</font>';
        $txt .= '<font color="#ECE9FF"> 暴击获得</font>';
        $txt .= '<font color="#2FE5FF">' . $coin . '</font>';
        $txt .= '<font color="#ECE9FF"> 金币</font>';
        $ext = $user;
        $ext['type'] = self::CHAT_REBATE_GIFT_GIVE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push($this->topic_room, $txt, $ext);
    }

    public function lottery2Score($ext, $gift)
    {
        $txt = "<font color='#C3B9FF'>少侠，打开怒气宝箱，获得礼物</font>";
        $txt .= '<font color="#F783FF">价值</font>';
        $txt .= '<font color="#2FE5FF">' . $gift->price . '金币</font>';
        $txt .= '<font color="#C3B9FF">的至宝</font>';
        $txt .= '<font color="#F783FF">' . $gift->name . ' X ' . $gift->count . '</font>';
        $txt .= '<font color="#C3B9FF"> ，珠光宝气</font>';
        $ext['type'] = self::CHAT_LUCKY_TREE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }

    public function lottery2($ext, $gift)
    {
        $txt = '<font color="#47B79E">少侠，成功击败董卓，获得礼物</font>';
        $txt .= '<b><font color="#00FDFF">价值' . $gift->price . '金币</font></b>';
        $txt .= '<font color="#47B79E">的礼物</font>';
        $txt .= '<b><font color="#00FDFF">' . $gift->name . 'X' . $gift->count . '</font></b>';
        $txt .= '<font color="#47B79E">，名扬天下</font>';
        $ext['type'] = self::CHAT_LUCKY_TREE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }


    public function blindBoxReceive($acceptExt, $sendExt, $gift, $blindBoxGift)
    {
        $txt = "<font color='#ECE9FF'>打开了</font><font color='#B6A2FF'>{$sendExt['nickname']}</font>";
        $txt .= "<font color='#ECE9FF'>赠送的</font><font color='#2FE5FF'>{$gift->name}</font>";
        $txt .= "<font color='#ECE9FF'>开出</font>";
        $txt .= "<font color='#2FE5FF'>{$blindBoxGift['price']}</font><font color='#ECE9FF'>金币的</font><font color='#2FE5FF'>{$blindBoxGift['gift_name']}X{$blindBoxGift['number']} ！</font>";
        $acceptExt['type'] = self::CHAT_LUCKY_TREE;
        $acceptExt['action'] = 1;
        $topRoomExt = $acceptExt;

        if ($blindBoxGift['price'] >= 13140) {
            $acceptExt['show_area'][] = self::AREA_ALL;
            $acceptExt['show_area'][] = self::AREA_LUCKY;
            $acceptExt['show_label_id'] = [
                self::AREA_LUCKY,
            ];
            $this->push('room', $txt, $acceptExt);
            $topRoomExt['show_area'][] = self::AREA_ROOM;
            $topRoomExt['show_label_id'] = [
                self::AREA_ROOM,
            ];
            $this->push($this->topic_room, $txt, $topRoomExt);
        } else {
            $acceptExt['show_area'][] = self::AREA_ROOM;
            $acceptExt['show_area'][] = self::AREA_ALL;
            $acceptExt['show_label_id'] = [
                self::AREA_ROOM,
            ];
            $this->push($this->topic_room, $txt, $acceptExt);
        }
    }

    public function blindBoxSend($ext, $notifyData, $userInfo, $count)
    {
        $txt = "<font color='#FFDFB4'>送给</font>";
        $txt .= "<font color='#B08DFF'>{$userInfo['nickname']}</font>";
        $txt .= '<font color="#FFFFFF"> 价值</font> <font color="#2FE5FF">' . $notifyData['price'] . '</font>';
        $txt .= '<font color="#FFFFFF"> 金币的 </font>';
        $txt .= '<font color="#2FE5FF">' . $notifyData['name'] . ' x ' . $count . '</font>';
        $txt .= '<font color="#FFFFFF"> 宝物</font>';
        $ext['type'] = self::CHAT_LUCKY_TREE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }

    public function getGroup($targetId)
    {
        return "group_" . $targetId;
    }

    public function getUser($userId)
    {
        return "user_" . $userId;
    }

    public function groupTextMessage($msgId, $groupId, $userId, $content)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_TEXT_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "message" => $content,
            "type" => self::GROUP_CHAT_TEXT_MESSAGE,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupAtUserMessage($msgId, $groupId, $userId, array $content)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_AT_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "message" => $content,
            "type" => self::GROUP_CHAT_AT_MESSAGE,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupImageMessage($msgId, $groupId, $userId, $image)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_IMAGE_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "message" => [
                'media' => $image,
            ],
            "type" => self::GROUP_CHAT_IMAGE_MESSAGE,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupAudioMessage($msgId, $groupId, $userId, $audio)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_AUDIO_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "message" => [
                'media' => $audio,
            ],
            "type" => self::GROUP_CHAT_AUDIO_MESSAGE,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupVideoMessage($msgId, $groupId, $userId, $video)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_VIDEO_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "message" => [
                'media' => $video,
            ],
            "type" => self::GROUP_CHAT_VIDEO_MESSAGE,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupBulletinMessage($msgId, $groupId, $userId, $bulletin)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_BULLETIN_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "message" => $bulletin,
            "type" => self::GROUP_CHAT_BULLETIN_MESSAGE,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupPositionMessage($msgId, $groupId, $userId, array $position)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_POSITION_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "message" => $position,
            "type" => self::GROUP_CHAT_POSITION_MESSAGE,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupShareRoomMessage($msgId, $groupId, $userId, $room)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_SHARE_ROOM_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "type" => self::GROUP_CHAT_SHARE_ROOM_MESSAGE,
            "message" => $room,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupSharePartyMessage($msgId, $groupId, $userId, $party)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_SHARE_PARTY_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "type" => self::GROUP_CHAT_SHARE_PARTY_MESSAGE,
            "message" => $party,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupShareCardMessage($msgId, $groupId, $userId, $card)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_CHAT_SHARE_CARD_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "type" => self::GROUP_CHAT_SHARE_CARD_MESSAGE,
            "message" => $card,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function groupGiftMessage($msgId, $groupId, $userId, $gift)
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = "GROUP_GIFT_MESSAGE";
        $ext = [
            "msg_id" => $msgId,
            "type" => self::GROUP_CHAT_GIFT_MESSAGE,
            "message" => $gift,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    /**
     * @param $msgId
     * @param $groupId
     * @param $userId
     * @param $content
     * @param array $users 用户信息 [] user_id, nickname
     * @param string[] $targetObject
     * @param array $targetUserIds
     */
    public function groupNotifyMessage($msgId, $groupId, $userId, $content, $messageType = "GROUP_NOTIFY_MESSAGE", $users = [], $targetUserIds = [])
    {
        $topic = $this->getGroup($groupId);
        $sender = $this->getUser($userId);
        $message = $messageType;
        $ext = [
            "msg_id" => $msgId,
            "message" => [
                "content" => $content,
                "users" => $users,
                "target_users" => $targetUserIds,
                "notify_type" => $messageType,
            ],
            "type" => self::GROUP_CHAT_NOTIFY_MESSAGE,
            "sender" => RedisService::getUserGroupChatLabel($userId, $groupId),
            'dnd_users' => [],
        ];
        $this->push($topic, $message, $ext, $sender);
    }

    public function unlockFriendCardMessage($userId, $targetId, $ext = [], $type = "HS:LoveLineMsg")
    {
        $senderId = $this->getUser($userId);
        $targetId = $this->getUser($targetId);

        $message = "明人不说暗话，想和你互动一下";
        $ext["type"] = self::CHAT_UNLOCK_CARD;
        $this->push($targetId, $message, $ext, $senderId, $type, 1);
    }

    public function lotteryStellarNew($ext, $gift)
    {
        // $txt = "<font color='#F17522'>" . $ext['nickname'] . "</font>";

        $txt = "<font color='#75CEFE'>在幸运神灯中获得了</font>";

        $txt .= '<font color="#FDA94E">价值' . $gift->price . '</font>';
        $txt .= '<font color="#75CEFE">金币的</font>';
        //$txt .= "<font color='#22C4F1'>的 </font>";
        $txt .= '<font color="#4DDB96">' . $gift->name . ' x ' . $gift->count . '</font>';
        $ext['type'] = self::CHAT_NEW_PIRATE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }

    public function lotterySeniorNew($ext, $gift)
    {
        // $txt = "<font color='#F17522'>" . $ext['nickname'] . "</font>";

        $txt = "<font color='#22C4F1'>在星动游乐场-豪华转盘中获得了</font>";

        $txt .= '<font color="#FFA41C">价值' . $gift->price . '</font>';
        $txt .= '<font color="#22C4F1">金币</font>';
        $txt .= "<font color='#22C4F1'>的 </font>";
        $txt .= '<font color="#FFF4B3">' . $gift->name . ' x ' . $gift->count . '</font>';
        $ext['type'] = self::CHAT_NEW_PIRATE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }

    public function lotteryPetNewV1($ext, $giftData,$broadcastPushData)
    {
        $txt = "<font color='#C5A1FF'>在金耀魔盒中获得了</font>";
        foreach ($giftData as $key => $value) {
            $txt .= '<font color="#FFC07D">价值' . $value->price . '</font>';
            $txt .= '<font color="#C5A1FF">金币的</font>';
            //$txt .= "<font color='#22C4F1'> </font>";
            $txt .= '<font color="#72D1E0">' . $value->name . ' x ' . $value->count .'.'.'</font>';

        }
        $ext['type'] = self::CHAT_NEW_PIRATE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];

        // ['broadcastPush'=> {} , 'notifyPush'=> {}]


        $this->push('room', $txt, $ext);
    }

    public function lotteryPetNew($ext, $gift)
    {
        // $txt = "<font color='#F17522'>" . $ext['nickname'] . "</font>";

        $txt = "<font color='#C5A1FF'>在金耀魔盒中获得了</font>";

        $txt .= '<font color="#FFC07D">价值' . $gift->price . '</font>';
        $txt .= '<font color="#C5A1FF">金币的</font>';
        //$txt .= "<font color='#22C4F1'> </font>";
        $txt .= '<font color="#72D1E0">' . $gift->name . ' x ' . $gift->count . '</font>';

        $ext['type'] = self::CHAT_NEW_PIRATE;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }


    public function lotteryPet($ext, $gift)
    {
        $txt = "<font color='#3F3A75'>" . $ext['nickname'] . "</font>";
        $txt .= "<font color='#3F3A75'>获得了</font>";

        $txt .= '<font color="#FF7200">价值' . $gift->price . '</font>';
        $txt .= '<font color="#FF7200">金币</font>';
        $txt .= "<font color='#3F3A75'>的 </font>";
        $txt .= '<font color="#BA59FF">' . $gift->name . ' x ' . $gift->count . '</font>';
        $ext['type'] = self::CHAT_PET;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];
        $this->push('room', $txt, $ext);
    }

    public function roomPKStart(int $roomId)
    {
        $message = "房间对决开启！";
        $ext = [
            "room_id" => $this->room_id,
            "type" => self::CHAT_ROOM_PK_START,
            "show_area" => [
                self::AREA_ALL,
                self::AREA_ROOM,
            ],
        ];
        $this->push($this->topic_room, $message, $ext);
    }

    public function roomPitPKStart(int $roomId)
    {
        $message = "团战对决开启！";
        $ext = [
            "room_id" => $roomId,
            "type" => self::CHAT_ROOM_PIT_PK_START,
            "show_area" => [
                self::AREA_ALL,
                self::AREA_ROOM,
            ],
        ];
        $this->push($this->topic_room, $message, $ext);
    }

    public function roomPKVictory(int $pkId, $room)
    {
        $message = '<font color="#FFFFE65C">恭喜</font>';
        $message .= '<font color="#FFFFE65C">' . $room->room_name . "</font>";
        $message .= '<font color="#FFFFE65C">在本轮房间PK中 获胜!</font>';
        $ext = [
            "type" => self::CHAT_ROOM_PK_VICTORY,
            "action" => 3,
            'pk_id' => $pkId,
            "room_id" => $this->room_id,
            "owner_room_id" => $room->id,
            "show_area" => [
                self::AREA_ALL,
                self::AREA_ROOM,
            ],
        ];
        $this->push($this->topic_room, $message, $ext);
    }

    public function roomPKDraw(int $pkId, int $roomId)
    {
        $message = '<font color="#FFFFE65C">双方 在本轮房间PK中 </font>';
        $message .= '<font color="#FFFFE65C">平分秋色</font>';
        $message .= '<font color="#FFFFE65C">!</font>';
        $ext = [
            "type" => self::CHAT_ROOM_PK_DRAW,
            "action" => 3,
            'pk_id' => $pkId,
            "room_id" => $this->room_id,
            "show_area" => [
                self::AREA_ALL,
                self::AREA_ROOM,
            ],
        ];
        $this->push($this->topic_room, $message, $ext);
    }

    public function roomPitPKVictory(int $pkId, int $roomId, int $camp)
    {
        $message = '<font color="#FFFFFF">恭喜 </font>';
        if ($camp == RoomPKEnum::PIT_PK_CAMP_RED) {
            $message .= '<font color="#DC8BDA">红方 </font>';
        } else {
            $message .= '<font color="#4FCCFF">蓝方 </font>';
        }

        $message .= '<font color="#FFFFFF">在本轮PK中 获胜!</font>';
        $ext = [
            "type" => self::CHAT_ROOM_PIT_PK_VICTORY,
            "action" => 3,
            'pk_id' => $pkId,
            "room_id" => $this->room_id,
            "camp" => $camp,
            "show_area" => [
                self::AREA_ALL,
                self::AREA_ROOM,
            ],
        ];
        $this->push($this->topic_room, $message, $ext);
    }

    public function roomPitPKDraw(int $pkId, int $roomId)
    {
        $message = '<font color="#FFFFE65C">双方 在本轮PK中 </font>';
        $message .= '<font color="#FFFFE65C">平分秋色</font>';
        $message .= '<font color="#FFFFE65C">!</font>';
        $ext = [
            "type" => self::CHAT_ROOM_PIT_PK_DRAW,
            "action" => 3,
            'pk_id' => $pkId,
            "room_id" => $this->room_id,
            "show_area" => [
                self::AREA_ALL,
                self::AREA_ROOM,
            ],
        ];
        $this->push($this->topic_room, $message, $ext);
    }

    public function roomPitPKDrawScore(int $pkId, int $roomId, int $redScore, int $blueScore)
    {
        $message = '<font color="#FFFFFF">双方平分秋色 蓝方</font>';
        $message .= '<font color="#FFFFE65C">' . $blueScore . '</font>';
        $message .= '<font color="#FFFFFF"> 红方</font>';
        $message .= '<font color="#FFFFE65C">' . $redScore . '</font>';
        $ext = [
            "type" => self::CHAT_ROOM_PIT_PK_DRAW_SCORE,
            "action" => 3,
            'pk_id' => $pkId,
            "room_id" => $this->room_id,
            "show_area" => [
                self::AREA_ALL,
                self::AREA_ROOM,
            ],
        ];
        $this->push($this->topic_room, $message, $ext);
    }


    public function lotteryCrystal($user, $prize, $ext)
    {
        $txt = "<font color='#ECE9FF'>{$user->nickname}</font>";
        $txt .= "<font color='#ECE9FF'>开启奇遇礼盒时得到了价值</font>";
        $txt .= "<font color='#ECE9FF'>{$prize->coin} 金币的</font>";
        $txt .= "<font color='#2FE5FF'>{$prize->name} X {$prize->count}</font>";
        $txt .= "<font color='#ECE9FF'>宝物</font>";
        $ext['type'] = self::CHAT_GASHAPON;
        $ext['action'] = 1;
        $ext['show_area'] = [
            self::AREA_LUCKY,
            // self::AREA_ALL,
        ];
        $ext['show_label_id'] = [
            self::AREA_LUCKY,
        ];

        $this->push('room', $txt, $ext);
    }

    public function accompanyMessage($userId, $targetId, $ext = [], $type = "MK:AccompanyCardMsg")
    {
        $senderId = $this->getUser($userId);
        $targetId = $this->getUser($targetId);

        $message = $ext['content'];
        $ext["type"] = self::CHAT_FIRST_ACCOMPANY;
        $this->push($targetId, $message, $ext, $senderId, $type, 0);
    }


    // 聊天室推送系统消息  $cmdName = $topic
    public function heartPushCmdMsg($cmdData, $topic = 'cmd', $senderId = 'system')
    {
        $type = $cmdData['type'];
        // 时间戳
        if (isset($cmdData['time'])) {
            $time = $cmdData['time'];
            unset($cmdData['time']);
        } else {
            $time = HelperService::microtime_float();
        }
        unset($cmdData['type']);
        $data = [
            'name' => $this->topic_heart,
            'uni_key' => uniqidReal(),
            'data' => ['msg' => $cmdData, 'type' => $type, 'time' => $time]
        ];
        $rcService = app('rongcloud');
        $queue = env("RABBITMQ_QUEUE");
        $rcService->queue($senderId, $this->topic_heart, $data, 0, 'RC:CmdMsg');
    }

    //心动连线推送文字消息
    public function heartPushTextMsg($targetId, $ext, $senderId = 'system')
    {
        $message = $ext['desc'];
        // $this->push($targetId, $message, $ext);
        $this->push($targetId, $message, $ext, $senderId, 'RC:TxtMsg', 0);
    }

    public function accompanyBrowseMessage($userId, $targetId, $ext = [], $type = "MK:AccompanyMeetMsg")
    {
        $senderId = $this->getUser($userId);
        $targetId = $this->getUser($targetId);

        $message = $ext['content'];
        $ext["type"] = self::CHAT_BROWSE_ACCOMPANY;
        $this->push($targetId, $message, $ext, $senderId, $type, 0);
    }
}

